<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>全局JavaScript变量</title>
</head>

<body>
    <h1>全局 JavaScript 变量</h1>
    <p>在函数外声明的变量是全局变量，网页上的所有脚本和函数都能访问它。</p>
    <script>
        var x = "007";
        function myFunction1() {
            alert(x);
        }
        function myFunction2() {
            alert(x);
        }
    </script>
    <button onclick="myFunction1()">点我1</button>
    <button onclick="myFunction2()">点我2</button>
</body>

</html>